/*
  The place everything lives in and the place where I keep all my stuff.
  Jonathan Leang 2010
  Capstone@jonathanleang.com
*/

public class World {
  // World textures
  Vector<String> worldTextureURL = new  Vector<String>();
  Vector<PImage> worldTexture = new  Vector<PImage>();
  Vector<Object> floors;
  
  // Sniffers
  Sniffer sniffer;
  ArrayList<Sniffer> sniffers;
  ArrayList<Node> nodes;
  
  World(ArrayList<Sniffer> sniffers, ArrayList<Node> nodes) {
    this.sniffers = sniffers;
    this.nodes = nodes;
    // Load texture
    
    this.floors = xml.getFloors();
    FLOOR_NUM = floors.size()/2;
    
    for(int i=0 ; i < FLOOR_NUM; i++){
        this.worldTextureURL.add(this.floors.elementAt(i*2).toString());
        this.worldTexture.add(loadImage(worldTextureURL.get(i)));
        this.worldTexture.get(i).resize(width,height);
    }
  }
  
  // Draw world
  void draw() {
    translate(width/2,height/2,-depth);
    
    noStroke();
    pushMatrix();
        // Draw all the sniffers
        drawSniffers();
        // Draw the map floor
        drawFloor(); // how many floors 
    popMatrix();
  }
  
  // Draw Sniffers 
  // Location using data from XML, Long Lat
  void drawSniffers(){
    pushMatrix();
      for (int i = 0; i < this.sniffers.size(); i++) {
      Sniffer each = this.sniffers.get(i);
      each.draw();
      }
    popMatrix();
    pushMatrix();
    for(int i=0;i < this.nodes.size();i++){
      Node each = this.nodes.get(i);
      each.draw();
    }
    popMatrix();
  }
  
  // mock up floor
  // load image and fill screen
  void drawFloor(){
    translate(-width/2,-height/2, 0);   
    for(int i=0 ; i < FLOOR_NUM; i++){
      pushMatrix();
        translate(0,0, i*FLOOR_HEIGHT);   
        tint(color(0,0,255), 100);
        fill(255,255,255);
        image(worldTexture.get(i),0,0);
      popMatrix();
    }
  }
}
